﻿Public Class Jugar
    Private x As Integer = 40

    Private Sub Jugar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        juego.palabraAzar()
        lblDescripcion.Text = juego._palabraActual.descripcion

        If juego._palabraActual.enunciado Is Nothing Then
            MessageBox.Show("Debes introducir palabras para jugar")
            Me.Close()
        Else

            For i = 0 To juego._palabraActual.enunciado.Length - 1
                Dim linea As New Label
                linea.Name = "linea" 'los nombres se pueden repetir
                linea.Visible = True
                linea.Text = "__"
                linea.Size = New Size(25, 25)
                linea.Location = New Point(x, 100)

                Me.Controls.Add(linea)
                x = x + 25
            Next
        End If


    End Sub




    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button30.Click, Button3.Click, Button29.Click, Button28.Click, Button27.Click, Button26.Click, Button25.Click, Button24.Click, Button23.Click, Button22.Click, Button21.Click, Button20.Click, Button19.Click, Button18.Click, Button16.Click, Button15.Click, Button14.Click, Button13.Click, Button12.Click, Button11.Click, Button10.Click
        Dim btnSender As Button = sender
        Dim letra As String
        letra = TryCast(sender, Object).text.tolower
        juego.PosicionesLetra(letra)

        If juego._palabraActual.enunciado.Contains(letra) Then
            btnSender.BackColor = Color.Green
            btnSender.Enabled = False
            If juego.Adivinado = True Then
                MessageBox.Show("Has acertado")

            End If
        Else
            If juego.Ahorcado = True Then
                MessageBox.Show("Ahorcado, Dale a otra palabra")

            End If
            btnSender.BackColor = Color.Red
            btnSender.Enabled = False
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOtra.Click
        For i = 0 To gbLetras.Controls.Count - 1
            gbLetras.Controls.Item(i).BackColor = Color.LightGray
            gbLetras.Controls.Item(i).Enabled = True
        Next
        x = 39
        juego.palabraAzar()
        lblDescripcion.Text = juego._palabraActual.descripcion

        Dim controles() As Control = Me.Controls.Find("linea", True)
        For i = 0 To controles.Length - 1
            Me.Controls.Remove(controles(i))
        Next

        For i = 0 To juego._palabraActual.enunciado.Length - 1
            Dim linea As New Label
            linea.Name = "linea" 'los nombres se pueden repetir
            linea.Visible = True
            linea.Text = "__"
            linea.Size = New Size(25, 25)
            linea.Location = New Point(x, 100)

            Me.Controls.Add(linea)
            x = x + 25
        Next
    End Sub

    Private Sub btnFinalizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinalizar.Click
        Me.Close()
        juego.Reiniciar()
    End Sub
End Class